﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

// maybe to be removed
using WtcrMvc.Models;

namespace WtcrMvc.MVVC {
    [DisplayName()]
    public class ContactMVVC {
        #region instance variables
        private Contact contact;
        private Person person;
        private Company company;
        #endregion

        #region constructors
        public ContactMVVC()
        {
            this.ContactsCompanies = new HashSet<Company>();
            this.ContactsCompanyContacts = new HashSet<CompanyContact>();
            this.ContactNotes = new HashSet<ContactNote>();
            this.ContactsPeople = new HashSet<Person>();
        }
        #endregion

        #region properties
        #region contactMVVC properties
        public Guid Id { get; set; }
        #endregion

        #region contact properties
        [DisplayName("Contact ID")]
        [ReadOnly(true)]
        public Guid ContactId { get; set; }

        [DisplayName("Full Name")]
        [StringLength(100)]
        [Required(AllowEmptyStrings=false)]
        public string ContactFullName { get; set; }

        [DisplayName("Created In")]
        [DataType(DataType.DateTime)]
        [ReadOnly(true)]
        public DateTime ContactCreatedIn { get; set; }

        [DisplayName("Last Update")]
        [DataType(DataType.DateTime)]
        [ReadOnly(true)]
        public DateTime ContactLastUpdate { get; set; }
        #endregion

        #region person properties
        [DisplayName("Person ID")]
        [ReadOnly(true)]
        public Guid PersonId { get; set; }

        //public Guid ContactId { get; set; }
        
        [DisplayName("Company")]
        [Description("The company the person works with.")]
        public Nullable<System.Guid> PersonCompanyId { get; set; }

        [StringLength(10)]
        public string Title { get; set; }

        [DisplayName("First Name")]
        [StringLength(32)]
        public string FirstName { get; set; }

        [DisplayName("Middle Name")]
        [StringLength(32)]
        public string MiddleName { get; set; }

        [DisplayName("Last Name")]
        [StringLength(32)]
        [Required]
        public string LastName { get; set; }

        [DisplayName("Is system user")]
        [DefaultValue(false)]
        [Required]
        public bool IsSystemUser { get; set; }

        [DisplayName("User ID")]
        [ReadOnly(true)]
        public Nullable<System.Guid> UserId { get; set; }

        [DisplayName("Person created in")]
        [DataType(DataType.DateTime)]
        public System.DateTime PersonCreatedIn { get; set; }

        [DisplayName("Person last update")]
        [DataType(DataType.DateTime)]
        public System.DateTime PersonLastUpdate { get; set; }
        #endregion

        #region company properties

        #endregion
        #endregion

        #region relations
        #region contact relations
        public virtual ICollection<Company> ContactsCompanies { get; set; }
        public virtual ICollection<CompanyContact> ContactsCompanyContacts { get; set; }
        public virtual ICollection<ContactNote> ContactNotes { get; set; }
        public virtual ICollection<Person> ContactsPeople { get; set; }
        #endregion

        #region person relations
        public virtual Company Company { get; set; }
        public virtual ICollection<Consultant> Consultants { get; set; }
        public virtual Contact PersonContact { get; set; }
        public virtual ICollection<Employee> Employees { get; set; }
        public virtual User User { get; set; }
        public virtual ICollection<PersonAddress> PersonAddresses { get; set; }
        public virtual ICollection<PersonNote> PersonNotes { get; set; }
        #endregion 

        #region company relations
        public virtual Contact CompanyContact { get; set; }
        public virtual ICollection<CompanyAddress> CompanyAddresses { get; set; }
        public virtual ICollection<CompanyContact> CompanysContacts { get; set; }
        public virtual ICollection<CompanyNote> CompanyNotes { get; set; }
        public virtual ICollection<Customer> Customers { get; set; }
        public virtual ICollection<Person> CompanysPeople { get; set; }
        public virtual ICollection<Supplier> Suppliers { get; set; }
        #endregion
        #endregion

        #region operators
        /// <summary>
        /// An explicit conversion operator from Contact to ContactMVVC
        /// </summary>
        /// <param name="contact">The contact to be converted</param>
        /// <returns>The corresponding ContactMVVC</returns>
        public static explicit operator ContactMVVC(Contact contact) {
            return new ContactMVVC() {
                ContactId = contact.Id,
                ContactFullName = contact.FullName,
                ContactCreatedIn = contact.CreatedIn,
                ContactLastUpdate = contact.LastUpdate,
                ContactsCompanies = contact.Companies,
                ContactsCompanyContacts = contact.CompanyContacts,
                ContactNotes = contact.ContactNotes,
                ContactsPeople = contact.People
            };
        }
        #endregion
    }
}